package com.zyl.simpletextwidget;

 
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.RemoteViews;

public class SimpleTextWidgetProvider extends AppWidgetProvider
{
  private static int getGravity(int paramInt)
  {
    int i = 3;
    switch (paramInt)
    {
    default: i = 3;break;
    case 1: i = 17;break;
    case 2:i = 5;break;
    }
      return i;
  }

  private static int getTextSize(int paramInt)
  {
    int i = 18;
    switch (paramInt)
    {
		default:
			i = 18;
			break;
		case 1:
			i = 20;
			break;
		case 2:
			i = 22;
			break;
		case 3:
			i = 24;
			break;
    }
      return i;
  }

  private static int setColor(int paramInt1, int paramInt2)
  {
    if (paramInt1 == 1)
      --paramInt2;
    int i = 0;
    switch (paramInt2)
    {
    default:
    	  i = 0;
    	  break;
    case -1:
    	 i = -16777216;
    	  break;
    case 0:
    	  i = -7829368;
    	  break;
    case 1:
    	i = -1;
    	  break;
    case 2:
    	i = -65536;
    	  break;
    case 3:
    	i = -256;
    	  break;
    case 4:
    	i = -256;
    	  break;
    case 5:
    	i = -16711936;
    	  break;
    case 6:
    	i = -16776961;
    	  i = 0;
    	  break;
    }
      return i;
  }

  private static void setOnClickIntent(Context paramContext, RemoteViews paramRemoteViews, int paramInt, Intent paramIntent)
  {
    paramRemoteViews.setOnClickPendingIntent(paramInt, PendingIntent.getActivity(paramContext, 0, paramIntent, 0));
  }

  public static void updateTextAppWidget(Context paramContext, AppWidgetManager paramAppWidgetManager, int paramInt1, String paramString, int paramInt2, int paramInt3, int paramInt4)
  {
	  RemoteViews localRemoteViews = new RemoteViews(paramContext.getPackageName(), 2130903042);
	    localRemoteViews.setFloat(R.id.widget_text, "setTextSize", getTextSize(paramInt3));
	    localRemoteViews.setInt(R.id.widget_layout, "setGravity", getGravity(paramInt4));
	    localRemoteViews.setTextColor(R.id.widget_text, setColor(2, paramInt2));
	    localRemoteViews.setTextViewText(R.id.widget_text, paramString);
	    Intent localIntent = new Intent(paramContext, SimpleTextWidgetConfigure.class);
	    localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	    localIntent.putExtra("appWidgetId", paramInt1);
	    localIntent.setData(ContentUris.withAppendedId(Uri.EMPTY, paramInt1));
	    setOnClickIntent(paramContext, localRemoteViews, R.id.widget_layout, localIntent);
	    paramAppWidgetManager.updateAppWidget(paramInt1, localRemoteViews);
  }

  public void onDeleted(Context paramContext, int[] paramArrayOfInt)
  {
    int i = paramArrayOfInt.length;
    for (int j = 0; ; ++j)
    {
      if (j >= i)
        return;
      SimpleTextWidgetConfigure.deletePref(paramContext, paramArrayOfInt[j]);
    }
  }

  public void onUpdate(Context paramContext, AppWidgetManager paramAppWidgetManager, int[] paramArrayOfInt)
  {
    int i = paramArrayOfInt.length;
    for (int j = 0; ; ++j)
    {
      if (j >= i)
        return;
      int k = paramArrayOfInt[j];
      updateTextAppWidget(paramContext, paramAppWidgetManager, k, SimpleTextWidgetConfigure.loadTextPref(paramContext, k), SimpleTextWidgetConfigure.loadTextColorPref(paramContext, k), SimpleTextWidgetConfigure.loadTextSizePref(paramContext, k), SimpleTextWidgetConfigure.loadGravityPref(paramContext, k));
    }
  }
}

